﻿var PropertyEdit = new Class({
    //加裁租售数据
    LoadRentAndSaleJson: function () {
        this.RentAndSaleJson = RentAndSaleJson;
        //将子类对象转入父类执行父类的方法
        this.base.LoadRentAndSaleJson.apply(this, arguments);
    },
    //特殊验证
    SpeVerify: function () {
        agencyVerify.mobileInput("#saveProperyEditForm", "#saveProperyEditForm :text[name=EditMobile]", true);

        var status = Number($("#propertyStatus").val());
        $("#saveProperyEditForm").bind("submit", function () {
            if (status < 3) {
                if (!$("#saveProperyEditForm input[name=EditMobile]")[0]) {
                    $.OKDialogAgency('<div class="tc">该状态下必须留有一个委托人手机！</div>');
                    return false;
                }
            }
        });
    },

    //权限显示
    bindRight: function () {
        var allnoedit = 0;
        if ($("#hidPermissions").val().indexOf("Property.BasicInformation.Modify") == -1) {
            $("#basicInfo").hide();
            allnoedit++;
        }
        if (
            ($("#hidPermissions").val().indexOf("Property.ContactInformation.Modify") == -1
            && $("#hidPermissions").val().indexOf("Property.ContactInformation.Add") == -1)

           || ($("#hidPermissions").val().indexOf("Property.ContactInformation.Search-IsDept") == -1
             && $("#hidPermissions").val().indexOf("Property.ContactInformation.Search-NoDept") == -1)

           || $("#hidDepartmentPermissions").val().indexOf("Property.ContactInformation.Search") == -1
           ) {
            $("#delegatePersonInfo").hide();
            $("#btnShowTrustor").hide();
            allnoedit++;
        }
        if ($("#hidPermissions").val().indexOf("Property.TransactionInformation.Modify") == -1) {
            $("#trustdiv").hide();
            allnoedit++;
        }
        if ($("#hidPermissions").val().indexOf("Property.PropertyCardInformation.Modify") == -1) {
            $("#propertyCardDiv").hide();
            allnoedit++;
        }
        if ($("#hidPermissions").val().indexOf("Property.ReferralInformation.Modify") == -1) {
            $("#referralInformationDiv").hide();
            allnoedit++;
        }
        if (allnoedit == 5) {
            $("#infosafe").hide();
        }
    },
    //选择默认租售及房户型的联动显示
    chooseTrust: function () {
        var TrustTyperadio = $("input[name=TrustType]");
        if ($("#consignInfo").attr("TrustType")) {
            TrustTyperadio.each(function () {
                if (this.value == $("#consignInfo").attr("TrustType")) {
                    this.click();
                }
            });
        } else { //框架房无交易类型
            $("input[name=TrustType][value=1]").click();
        }
    },
    //显示编辑联系人逻辑
    showTrust: function (a) {
        $.AjaxAgency("/Property/trustors-for-log-ajax", { 'keyId': $("input[name=keyId]").val() }, function (data) {
            if (data.CanBrowse) {
                $("#delegatePersonInfo").show();
                $(a).attr("disabled", "disabled");
                $("#check").val(true);
                var result = false;
                var type = dataBind.getRealDataByType(98);
                if (data.Trustors.length > 0) {
                    if (type[0].ExtendAttr == "1" && (data.Trustors[0].ShortCount > 0 || data.Trustors[0].LongCount > 0)) {
                        result = true;
                        }
                }
                if (result == false) {
                     if (type[0].ExtendAttr == "1") {
                         $("input[name=TrustorName]").attr("isnull", "isNull");
                    }
                    else if (data.RemainingBrowseCount >= 0) {
                        $("input[name=TrustorName]").attr("isnull", "isNull");
                        $(a).val("您已经查看了" + data.UsedBrowseCount + "次,您还可以查看" + data.RemainingBrowseCount + "次");
                    }
                }
               
            }
            else {
                $("#check").val(false);
                $(a).attr("disabled", "disabled");
                if (typeof data === "string") {
                    $(a).val(data);
                }
                else {
                    $(a).val(data.NoCallMessage);
                }
            }
        });
    }
}, PropertyAddandEdit);
